var api = require('./api.js');
var utils = require('../utils/util.js');

// 网络请求
function request(url,type, data, successCb, errorCb, completeCb) {
    wx.request({
        url: url,
        method: type,
        data: data,
        success: function(res) {
            // console.log(res)
            if (res.statusCode == 200){
                utils.isFunction(successCb) && successCb(res.data);
            }else{
                console.log('请求异常', res);
            }
        },
        error: function() {
            utils.isFunction(errorCb) && errorCb();
        },
        complete: function() {
            utils.isFunction(completeCb) && completeCb();
        }
    });
}

//首页banner、每日推荐
function requestBannerList( data, successCb, errorCb, completeCb){
    request(api.API_BANNERLIST, 'GET', data, successCb, errorCb, completeCb);
}
//最新测试列表
function requestNewsList( data, successCb, errorCb, completeCb){
    request(api.API_NEWSLIST, 'GET', data, successCb, errorCb, completeCb);
}
//热门测试列表
function requestHotList( data, successCb, errorCb, completeCb){
    request(api.API_HOTLIST, 'GET', data, successCb, errorCb, completeCb);
}
//开始答题
function requestStarttest( data, successCb, errorCb, completeCb){
    request(api.API_STARTTEST, 'GET', data, successCb, errorCb, completeCb);
}
//问题列表
function requestQUestionList( data, successCb, errorCb, completeCb){
    request(api.API_QUESTIONLIST, 'GET', data, successCb, errorCb, completeCb);
}
//查询结果
function requestTestResult( data, successCb, errorCb, completeCb){
    request(api.API_TESTRESULT, 'GET', data, successCb, errorCb, completeCb);
}
//登录
function requestLogin(data, successCb, errorCb, completeCb) {
  request(api.API_login, 'GET', data, successCb, errorCb, completeCb);
}
//提交反馈
function requestSubAdvise(data, successCb, errorCb, completeCb) {
    request(api.API_SUBADVISE, 'GET', data, successCb, errorCb, completeCb);
}
//我的测试
function requestMyTest(data, successCb, errorCb, completeCb) {
  request(api.API_MYTEST, 'GET', data, successCb, errorCb, completeCb);
}
//查看测试结果
function requestViewResult(data, successCb, errorCb, completeCb) {
  request(api.API_VIEWRESULT, 'GET', data, successCb, errorCb, completeCb);
}
//点赞
function requestDianZan(data, successCb, errorCb, completeCb) {
  request(api.API_ZAN, 'GET', data, successCb, errorCb, completeCb);
}

module.exports = {
  requestBannerList:requestBannerList,    //首页banner、每日推荐
  requestNewsList:requestNewsList,         //最新测试列表
  requestHotList:requestHotList,          //热门测试列表
  requestStarttest:requestStarttest,       //开始测试
  requestQUestionList:requestQUestionList,   //问题列表
  requestTestResult:requestTestResult,   //查询结果
  requestSubAdvise: requestSubAdvise,      //提交反馈
  requestMyTest: requestMyTest,      //我的测试
  requestViewResult: requestViewResult,      //查看测试结果
  requestDianZan: requestDianZan,      //点赞
}
